package com.haoshuang.zhouzhoubang.ui.page.home.settings.skill.add

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.SkillAddBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class AddSkillListViewModel : BaseViewModel() {

    /**
     * 获取添加技能展示列表
     */
    val getAddSkillListData = StatefulMutableLiveData<ResponseBean<MutableList<SkillAddBean>>>()
    fun getAddSkillList(type: Int) = netRequest {
        start { getAddSkillListData.value = StateData.Loading }
        request { ApiRepo.getAddSkillList(type) }
        success { getAddSkillListData.value = StateData.Success(it) }
        error { code, msg ->
            getAddSkillListData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 添加技能
     */
    val updateTeamCategoryData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun updateTeamCategory(service_ids: String, small_ids: String, little_ids: String) =
        netRequest {
            start { updateTeamCategoryData.value = StateData.Loading }
            request { ApiRepo.updateTeamCategory(service_ids, small_ids, little_ids) }
            success { updateTeamCategoryData.value = StateData.Success(it) }
            error { code, msg ->
                updateTeamCategoryData.value = StateData.Error(code, msg)
            }
        }

    /**
     * 移除技能
     */
    val undockTeamCategoryData = StatefulMutableLiveData<Any>()
    fun undockTeamCategory(first_ids: String, small_ids: String, ids: String) = netRequest {
        start { undockTeamCategoryData.value = StateData.Loading }
        request { ApiRepo.undockTeamCategory(first_ids, small_ids, ids)  }
        success { undockTeamCategoryData.value = StateData.Success(it.data) }
        error { code, msg ->
            undockTeamCategoryData.value = StateData.Error(code, msg)
        }
    }

}